{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-1"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import cv2\n",
    "# cv2.imread()报括4个过程：文件读取，封装格式解析，数据编码，数据加载。\n",
    "img= cv2.imread('image0.jpg',1)\n",
    "cv2.imshow('image',img)\n",
    "# 常用的图片格式：jpg png 文件由文件头和文件数据组成 \n",
    "# 文件数据不是原始的数据而是要根据文件头中的压缩编码等信息进行还原\n",
    "cv2.waitKey(0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 图片写入\n",
    "import cv2\n",
    "img= cv2.imread('image0.jpg',1)\n",
    "# 第一个参数 写入的文件名 第二个参数为文件数据（已经解码后的数据，即图片的原始数据（经过imread处理））\n",
    "cv2.imwrite('image1.jpg',img)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
